package thread;

class Singleton01 {
    private Singleton01() {}

    private static Singleton01 instance = new Singleton01();

    public static Singleton01 getInstance() {
        return instance;
    }
}

    class Singleton02{
        private Singleton02() {}
        private static Singleton02 instance;
        public static Singleton02 getInstance(){
            if (instance==null){
                instance = new Singleton02();
            }
            return instance;
        }
}

class Singleton03{
    private Singleton03() {}
    private static Singleton03 instance;
    public static synchronized Singleton03 getInstance(){
        if (instance==null){
            instance = new Singleton03();
        }
        return instance;
    }
}

public class SingletonDemo01 {
    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i1 = 0; i1 < 10; i1++) {
                    Singleton02 singleton02 = Singleton02.getInstance();
                    System.out.println(singleton02);
                }

                }
        }).start();

            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int i1 = 0; i1 < 10; i1++) {
                        Singleton02 singleton02 = Singleton02.getInstance();
                        System.out.println(singleton02);
                    }

                }
            }).start();

        }
    }
}
